import { Rule, RuleType } from "@midwayjs/validate";
import { RelatedType } from "../entity/info";

const scoreItemRule = RuleType.object().keys({
    label: RuleType.string().required(),
    score: RuleType.number().required(),
}).required();

export class AddCommentDTO {
    @Rule(RuleType.number().required())
    relatedId: number;
    @Rule(RuleType.allow(RelatedType.PRODUCT, RelatedType.ORDER, RelatedType.PROVIDER, RelatedType.TEAM, RelatedType.CAR, RelatedType.SCHEDULE, RelatedType.INVITE).required())
    relatedType: RelatedType;
    @Rule(RuleType.string().required())
    content: string;
    @Rule(RuleType.array().items(RuleType.string()).min(0).default([]))
    images: string[];
    @Rule(RuleType.array().items(scoreItemRule))
    scoreList: {
        label: string;
        score: number;
    }[];
}

export class CommentListDTO {
    @Rule(RuleType.number().required())
    relatedId: number;
    @Rule(RuleType.allow(RelatedType.PRODUCT, RelatedType.ORDER, RelatedType.PROVIDER, RelatedType.TEAM, RelatedType.CAR, RelatedType.SCHEDULE, RelatedType.INVITE).required())
    relatedType: RelatedType;
}

export class AddInviteCommentDTO {
    @Rule(RuleType.string().required())
    inviteCode: string;
    @Rule(RuleType.string().required())
    content: string;
    @Rule(RuleType.array().items(RuleType.string()).min(0).default([]))
    images: string[];
    @Rule(RuleType.array().items(scoreItemRule))
    scoreList: {
        label: string;
        score: number;
    }[];
}

export class UserCommentPageDTO {
    @Rule(RuleType.number().min(1).default(1))
    page: number;

    @Rule(RuleType.number().min(1).max(100).default(10))
    size: number;
}